package com.hwl.lab.service;

import com.hwl.lab.entity.Area;
import com.hwl.lab.entity.Institution;
import com.hwl.lab.repository.AreaRepository;
import com.hwl.lab.repository.InstitutionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InstitutionService {
    @Autowired
    private InstitutionRepository institutionRepository;
    //分页实现
    public Page<Institution> findAll(Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return institutionRepository.findAll(pageable);
    }
    //不分页
    public List<Institution> findAll() {
        return institutionRepository.findAll();
    }
    //保存，修改
    public Institution saveInstitution(Institution institution){
       return  institutionRepository.save(institution);
    }

    public void deleteById(String id) {
        institutionRepository.deleteByInstitutionid(id);
    }

    public void deleteByInstitutionid(String institutionid) {
        institutionRepository.deleteByInstitutionid(institutionid);
    }
}
